package com.yidu.hbatsams.action.emp;

import com.yidu.hbatsams.domain.*;
import com.yidu.hbatsams.domain.vo.UserVo;
import com.yidu.hbatsams.utils.Tools;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: 人员管理word数据填充类
 * @description:
 * @author: 张超
 * @create: 2019-12-02 15:30
 */
public class EmpWordAddData {

    public XWPFDocument exportWord(Object object, int type, String contextPath, HttpSession session){

        EmpExportWord ew = new EmpExportWord(type);
        XWPFDocument document = ew.createXWPFDocument();
        List<List<Object>> list = new ArrayList<List<Object>>();
        Map<String, Object> dataList = null;


        if(type==1){
            AtsEmpAthlete atsEmpAthlete = (AtsEmpAthlete)object;
            UserVo user = (UserVo) session.getAttribute("user");
            List<Object> tempList = new ArrayList<Object>();
            tempList.add("运动员名称");
            tempList.add(atsEmpAthlete.getAthleteName());
            tempList.add("部门名称");
            tempList.add(atsEmpAthlete.getDeptName());
            tempList.add("岗位名称");
            tempList.add(atsEmpAthlete.getPostName());
            list.add(tempList);
            tempList = new ArrayList<Object>();
            tempList.add("注册单位");
            tempList.add(atsEmpAthlete.getOrganName());
            tempList.add("联系方式");
            tempList.add(atsEmpAthlete.getPhone());
            tempList.add("毕业院校");
            tempList.add(atsEmpAthlete.getGraduateSchool());
            list.add(tempList);
            tempList = new ArrayList<Object>();
            tempList.add("打法");
            tempList.add(atsEmpAthlete.getPlay());
            tempList.add("俱乐部");
            tempList.add(atsEmpAthlete.getClub());
            tempList.add("进队时间");
            tempList.add(atsEmpAthlete.getJoinTime());
            list.add(tempList);
            tempList = new ArrayList<Object>();
            tempList.add("出生年月");
            tempList.add(atsEmpAthlete.getBirthday());
            tempList.add("训练年限");
            tempList.add(atsEmpAthlete.getTrainingYears());
            tempList.add("籍贯");
            tempList.add(atsEmpAthlete.getNativePlace());
            list.add(tempList);
            tempList = new ArrayList<Object>();
            tempList.add("习惯手");
            tempList.add(atsEmpAthlete.getHand());
            tempList.add("性别");
            tempList.add(atsEmpAthlete.getAthleteSex());
            tempList.add("技术等级");
            tempList.add(atsEmpAthlete.getLevel());
            list.add(tempList);
            tempList = new ArrayList<Object>();
            tempList.add("文化程度");
            tempList.add(atsEmpAthlete.getEducation());
            tempList.add("最好成绩");
            tempList.add(atsEmpAthlete.getBestResult());
            tempList.add("教练员");
            tempList.add(atsEmpAthlete.getCoachName());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("导出人");
            tempList.add(user.getUserName());
            tempList.add("导出时间");
            tempList.add(Tools.getCurDateTime());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("家庭情况");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpAthlete.getFamily());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("运动员说明");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpAthlete.getAthleteExp());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("通讯地址");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpAthlete.getAddr());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("其他说明");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpAthlete.getOther());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("技术特征");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpAthlete.getTechnical());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("战术特征");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpAthlete.getTactics());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("心理特征");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpAthlete.getMentality());
            list.add(tempList);

            dataList = new HashMap<String, Object>();
            dataList.put("TITLE", "运动员信息");
            dataList.put("TABLEDATA", list);
        }else if(type==2){
            AtsEmpCoach atsEmpCoach = (AtsEmpCoach)object;
            UserVo user = (UserVo) session.getAttribute("user");
            List<Object> tempList = new ArrayList<Object>();
            tempList.add("教练员姓名");
            tempList.add(atsEmpCoach.getCoachName());
            tempList.add("部门名称");
            tempList.add(atsEmpCoach.getDeptName());
            tempList.add("岗位名称");
            tempList.add(atsEmpCoach.getPostName());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("所在单位");
            tempList.add(atsEmpCoach.getOrganName());
            tempList.add("人员类型");
            tempList.add(atsEmpCoach.getCoachExp());
            tempList.add("专业");
            tempList.add(atsEmpCoach.getExpertSpecia());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("联系方式");
            tempList.add(atsEmpCoach.getPhone());
            tempList.add("导出人");
            tempList.add(user.getUserName());
            tempList.add("导出时间");
            tempList.add(Tools.getCurDateTime());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("通讯地址");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpCoach.getAddr());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("其他说明");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpCoach.getOther());
            list.add(tempList);

            dataList = new HashMap<String, Object>();
            dataList.put("TITLE", "教练员信息");
            dataList.put("TABLEDATA", list);
        }else if(type==3){
            AtsEmpExpert atsEmpExpert = (AtsEmpExpert)object;
            UserVo user = (UserVo) session.getAttribute("user");
            List<Object> tempList = new ArrayList<Object>();
            tempList.add("专家姓名");
            tempList.add(atsEmpExpert.getExpertName());
            tempList.add("部门名称");
            tempList.add(atsEmpExpert.getDeptName());
            tempList.add("岗位名称");
            tempList.add(atsEmpExpert.getPostName());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("所在单位");
            tempList.add(atsEmpExpert.getOranName());
            tempList.add("人员类型");
            tempList.add(atsEmpExpert.getExpertExp());
            tempList.add("专业");
            tempList.add(atsEmpExpert.getExpertSpecia());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("联系方式");
            tempList.add(atsEmpExpert.getPhone());
            tempList.add("导出人");
            tempList.add(user.getUserName());
            tempList.add("导出时间");
            tempList.add(Tools.getCurDateTime());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("通讯地址");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpExpert.getAddr());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("其他说明");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpExpert.getOther());
            list.add(tempList);

            dataList = new HashMap<String, Object>();
            dataList.put("TITLE", "专家信息");
            dataList.put("TABLEDATA", list);
        }else if(type==4){
            AtsEmpLeader atsEmpLeader = (AtsEmpLeader)object;
            UserVo user = (UserVo) session.getAttribute("user");
            List<Object> tempList = new ArrayList<Object>();
            tempList.add("领导姓名");
            tempList.add(atsEmpLeader.getLeaderName());
            tempList.add("部门名称");
            tempList.add(atsEmpLeader.getDeptName());
            tempList.add("岗位名称");
            tempList.add(atsEmpLeader.getPostName());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("负责事务");
            tempList.add(atsEmpLeader.getLeaderBusiness());
            tempList.add("职责说明");
            tempList.add(atsEmpLeader.getLeaderExp());
            tempList.add("联系方式");
            tempList.add(atsEmpLeader.getPhone());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("导出人");
            tempList.add(user.getUserName());
            tempList.add("");
            tempList.add("导出时间");
            tempList.add(Tools.getCurDateTime());
            tempList.add("");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("通讯地址");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpLeader.getAddr());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("其他说明");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add(atsEmpLeader.getOther());
            list.add(tempList);

            dataList = new HashMap<String, Object>();
            dataList.put("TITLE", "领导信息");
            dataList.put("TABLEDATA", list);
        }else if(type==5){
            AtsEmpAthleteResults atsEmpAthleteResults = (AtsEmpAthleteResults)object;
            UserVo user = (UserVo) session.getAttribute("user");
            List<Object> tempList = new ArrayList<Object>();
            tempList.add("运动员名称");
            tempList.add(atsEmpAthleteResults.getAthleteName());
            tempList.add("比赛名称");
            tempList.add(atsEmpAthleteResults.getMatchName());
            tempList.add("比赛时间");
            tempList.add(atsEmpAthleteResults.getMatchTime());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("比赛地点");
            tempList.add(atsEmpAthleteResults.getMatchAddr());
            tempList.add("比赛项目");
            tempList.add(atsEmpAthleteResults.getMatchItem());
            tempList.add("比赛成绩");
            tempList.add(atsEmpAthleteResults.getMatchResult());
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("比赛排名");
            tempList.add(atsEmpAthleteResults.getMatchSort());
            tempList.add("");
            tempList.add("积分");
            tempList.add(atsEmpAthleteResults.getScore());
            tempList.add("");
            list.add(tempList);

            tempList = new ArrayList<Object>();
            tempList.add("导出人");
            tempList.add(changeStr(user.getUserName()));
            tempList.add("");
            tempList.add("导出时间");
            tempList.add(Tools.getCurDateTime());
            tempList.add("");
            list.add(tempList);


            dataList = new HashMap<String, Object>();
            dataList.put("TITLE", "比赛成绩信息");
            dataList.put("TABLEDATA", list);
        }
        try {
            ew.exportCheckWord(dataList, document,contextPath);
            return document;
        } catch (IOException e) {
            e.printStackTrace();
            return  null;
        }

    }
    /**
     * 如果为空则返回""
     * @param str
     * @return
     */
    public String changeStr(String str){
        if(str!=null&&!"".equals(str)){
            return str;
        }else{
            return "";
        }
    }
}